package com.dnjn.happiness.emo.controller;

import com.dnjn.happiness.common.config.DateTimeFormatHolder;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.utils.poi.ExcelUtil;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.annotation.RequiresPermissions;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import com.dnjn.happiness.emo.controller.common.CommonUserRecordFerController;
import com.dnjn.happiness.emo.domain.UserRecordFer;
import com.dnjn.happiness.emo.domain.vo.UserRecordFerAddVO;
import com.dnjn.happiness.emo.domain.vo.UserRecordFerExportVo;
import com.dnjn.happiness.emo.domain.vo.UserRecordFerVO;
import com.dnjn.happiness.emo.service.IUserRecordFerService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

/**
 * 用户AI情绪userRecordFerController
 *
 * @author amber
 * @date 2023-12-04
 */
@Tag(name = "emo userRecordFer 用户AI情绪userRecordFer", description = "用户AI情绪userRecordFer")
@RestController
@RequestMapping("/userRecordFer")
public class UserRecordFerController extends CommonUserRecordFerController {
    @Autowired
    private IUserRecordFerService userRecordFerService;


    /**
     * 查询用户AI情绪userRecordFer列表
     */
    @Log(title = "用户AI情绪userRecordFer", businessType = BusinessType.LIST)
    @RequiresPermissions("@ss.hasAnyPermi('emo:userRecordFer:list,ignore:userRecordFer:list')")
    @PostMapping("/list")
    public AjaxResult list(@Validated @RequestBody UserRecordFerVO vo) {
        vo.setUserId(SecurityUtils.getUserId()); //only current user
        UserRecordFer userRecordFer = new UserRecordFer();
        BeanUtils.copyPropsIgnoreNull(vo, userRecordFer);
        userRecordFer.getParams().put("beginTime", DateTimeFormatHolder.FORMATTER_YYYY_MM_DD.format(vo.getDateStart()));
        userRecordFer.getParams().put("endTime", DateTimeFormatHolder.FORMATTER_YYYY_MM_DD.format(vo.getDateEnd()));

        List<UserRecordFer> list = userRecordFerService.listAll(userRecordFer);
        return AjaxResult.success(list);
    }

    /**
     * 导出用户AI情绪userRecordFer列表
     */
    @Log(title = "用户AI情绪userRecordFer", businessType = BusinessType.EXPORT)
    @RequiresPermissions("@ss.hasPermi('emo:userRecordFer:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserRecordFerAddVO vo) {
        UserRecordFer userRecordFer = new UserRecordFer();
        BeanUtils.copyPropsIgnoreNull(vo, userRecordFer);
        List<UserRecordFerExportVo> list = userRecordFerService.getExportList(userRecordFer);
        ExcelUtil<UserRecordFerExportVo> util = new ExcelUtil<UserRecordFerExportVo>(UserRecordFerExportVo.class);
        util.exportExcel(response, list, "用户AI情绪userRecordFer数据");
    }

}
